//-------------------------------------------------------------------------------
//	file CBuf.h
//	brief
//		Tiny buffer template class
//
//	$Id: CBuf.h 240 2014-02-09 06:17:18Z ac.verbeck@gmail.com $
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//	Copyright and Disclaimer Notice
//
//	Copyright (c) 2012 A.C. Verbeck
//	original author: Michel Helms (MichelHelms@Web.de).
//
//	This file is part of AudioCD: Audio CD function library
//
//	AudioCD is free software: you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation, either version 3 of the License, or
//	(at your option) any later version.
//
//	AudioCD is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with AudioCD.  If not, see <http://www.gnu.org/licenses/>.
//
//------------------------------------------------------------------------------
#pragma once

#include <malloc.h>

template<class Cl> class CBuf
{
public:
	CBuf()
	{
		m_pData = NULL;
		m_iSize = 0;
	}
	CBuf(ULONG Count)
	{
		m_pData = (Cl*)malloc((m_iSize=Count)*sizeof(Cl));
	}
	~CBuf()
	{
		Free();
	}

	Cl* Alloc(ULONG Count)
	{
		return m_pData = (Cl*) realloc(m_pData, (m_iSize=Count)*sizeof(Cl));
	}

	void Free()
	{
		free(m_pData);
		m_pData = NULL;
		m_iSize = 0;
	}

	ULONG Count()
	{
		return m_iSize;
	}

	ULONG Size()
	{
		return m_iSize*sizeof(Cl);
	}

	Cl* Ptr()
	{
		return m_pData;
	}

	operator Cl* ()
	{
		return m_pData;
	}

private:
	Cl*		m_pData;
	ULONG	m_iSize;
};

//
//	End: CBuf.h
//
